<?php

//从URI请求分析模块
function moduleCheck($uri)
{
	global $conf;
	if(preg_match('/\.\.\//', $_SERVER['QUERY_STRING']))goURL('/');
	if(is_file(ROOT_PATH."/modules/{$uri[0]}/{$uri[1]}.php"))$module = "{$uri[0]}/{$uri[1]}";
        elseif(is_file(ROOT_PATH."/modules/{$uri[0]}.php"))$module = $uri[0];
	else $module = $conf['default_module'];
	return $module;
}


//分析Action
function actionCheck($uri, $module)
{

	$depth = count(explode('/', $module));
	if($depth<count($uri))
	{
		return $uri[$depth];
	}
	else return $_REQUEST['action'];
}

//分析id
function idCheck($uri, $module, $ac)
{
	$depth = count(explode('/', $module));
	if($depth<count($uri)-1)
	{
		return $uri[$depth]+1;
	}
	else return '';
}

//将URL重写
function URLRewrite()
{
	global $conf;
	$get = $_GET;
	$module = $get['module'];
	$sub = $get['sub'];
	unset($get['module']);
	unset($get['sub']);
	$uri = $conf['site_url']."/?$module/$sub".implode('/', $get);

	return $uri;
}

//模块装载
function module($module)
{
	global $conf;
	$module = strtolower($module);
	$module_file = ROOT_PATH."/modules/$module.php";
	if(file_exists($module_file))return $module_file;
	else return ROOT_PATH."/modules/$conf[default_module].php";
	//else echo "Module $module not found!";
}

//设定cookie
function scookie($name, $value='', $time=null)
{
	global $conf;
	return setcookie($name, $value, $time, $conf['cookie_path'], $conf['cookie_host']);
}

function extfunc($func)
{
	global $conf;
	$path = ROOT_PATH.'/'.$conf['extend_path']."/functions.$func.php";
	if(is_file($path))return $path;
	else echo "Function $func not found!";
}


function extclass($func)
{
	global $conf;
	$path = ROOT_PATH.'/'.$conf['extend_path']."/class.$func.php";
	if(is_file($path))return $path;
	else echo "Class $func not found!";
}
?>